﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Security.AccessControl;

namespace System.Peppers.Wmi
{
    /// <summary>
    /// The Win32_ACE abstract WMI class specifies an access control entry (ACE). An ACE grants permission to execute a restricted operation, such as writing to a file or formatting a disk. An ACE that is specific to WMI allows logon, remote access, method execution, and writing to the WMI repository.
    /// </summary>
    public sealed class WmiAce : WmiWrapper
    {
        #region Static
        private static class WmiProperties
        {
            public const string AccessMask = "AccessMask",
                AceFlags = "AceFlags",
                AceType = "AceType",
                Trustee = "Trustee";
        }
        #endregion

        /// <summary>
        /// Creates a new instance
        /// </summary>
        public WmiAce()
            : base(new ManagementObject(WmiClasses.Win32_ACE))
        { }

        /// <summary>
        /// Bit flags that indicate rights granted or denied to the trustee. For more information, see the Remarks section of this topic.
        /// </summary>
        public FileSystemRights AccessMask
        {
            get { return (FileSystemRights)Convert.ToUInt32(this[WmiProperties.AccessMask] ?? 0); }
            set { this[WmiProperties.AccessMask] = value; }
        }

        /// <summary>
        /// Bit flags that specify inheritance of the ACE. The following table lists the relevant permission values for AceFlags.
        /// </summary>
        public AceFlags AceFlags
        {
            get { return (AceFlags)Convert.ToUInt32(this[WmiProperties.AceFlags] ?? 0); }
            set { this[WmiProperties.AceFlags] = value; }
        }

        /// <summary>
        /// Type of ACE.
        /// </summary>
        public AceType AceType
        {
            get { return (AceType)Convert.ToUInt32(this[WmiProperties.AceType] ?? 0); }
            set { this[WmiProperties.AceType] = value; }
        }
        
        /// <summary>
        /// Object representing the user account, group account, or logon session to which an ACE applies.
        /// </summary>
        public WmiTrustee Trustee
        {
            get { return this[WmiProperties.Trustee] as WmiTrustee; }
            set { this[WmiProperties.Trustee] = value; }
        }
    }
}
